package com.zjsd.sqeybusiness.service.impl;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.SysPost;
import com.sun.org.apache.bcel.internal.generic.SIPUSH;
import com.zjsd.sqeybusiness.domain.Achievements;
import com.zjsd.sqeybusiness.domain.Depttask;
import com.zjsd.sqeybusiness.dto.*;
import com.zjsd.sqeybusiness.mapper.DepttaskMapper;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zjsd.sqeybusiness.mapper.BusitaskMapper;
import com.zjsd.sqeybusiness.domain.Busitask;
import com.zjsd.sqeybusiness.service.IBusitaskService;

/**
 * 业务员目标任务Service业务层处理
 *
 * @author Zheng
 * @date 2021-07-14
 */
@Service
public class BusitaskServiceImpl implements IBusitaskService
{
    @Autowired
    private BusitaskMapper busitaskMapper;

    @Autowired
    private DepttaskMapper depttaskMapper;

    @Autowired
    private TokenService tokenService;
    /**
     * 查询业务员目标任务
     *
     * @param taskid 业务员目标任务ID
     * @return 业务员目标任务
     */
    @Override
    public Busitask selectBusitaskById(Long taskid)
    {
        return busitaskMapper.selectBusitaskById(taskid);
    }

    /**
     * 查询业务员目标任务列表
     *
     * @param busitask 业务员目标任务
     * @return 业务员目标任务
     */
    @Override
    public List<Busitask> selectBusitaskList(Busitask busitask)
    {
        return busitaskMapper.selectBusitaskList(busitask);
    }

    /**
     * 新增业务员目标任务
     *
     * @param busitask 业务员目标任务
     * @return 结果
     */
    @Override
    public int insertBusitask(Busitask busitask)
    {

        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser user = loginUser.getUser();
        Long deptid = user.getDeptId();
        Long userid = user.getUserId() ;
        busitask.setUserid( userid);
        busitask.setDeptid( deptid);
        busitask.setLrtime(new Date());
        busitask.setYwyname(loginUser.getUser().getNickName());
        List<Busitask> busitaskList = busitaskMapper.selectBusitaskList(busitask);
        if(busitaskList != null && busitaskList.size() > 0 ){
            throw new CustomException("已录入过所选月份任务");
        }
        return busitaskMapper.insertBusitask(busitask);
    }

    /**
     * 修改业务员目标任务
     *
     * @param busitask 业务员目标任务
     * @return 结果
     */
    @Override
    public int updateBusitask(Busitask busitask)
    {
        return busitaskMapper.updateBusitask(busitask);
    }

    /**
     * 批量删除业务员目标任务
     *
     * @param taskids 需要删除的业务员目标任务ID
     * @return 结果
     */
    @Override
    public int deleteBusitaskByIds(Long[] taskids)
    {
        return busitaskMapper.deleteBusitaskByIds(taskids);
    }

    /**
     * 删除业务员目标任务信息
     *
     * @param taskid 业务员目标任务ID
     * @return 结果
     */
    @Override
    public int deleteBusitaskById(Long taskid)
    {
        return busitaskMapper.deleteBusitaskById(taskid);
    }

    @Override
    public int insertDeptTask(DeptTaskDTO deptTaskDTO) {

        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser user = loginUser.getUser();
        Long deptid = user.getDeptId();
        Long userid = user.getUserId() ;

        List<Depttask> list = deptTaskDTO.getList() ;
        if(list != null && list.size() > 0 ){
            for(Depttask temp : list ){
                temp.setUserid(userid);
                temp.setLrtime(new Date());
                temp.setSsyf(deptTaskDTO.getSsyf());
                temp.setUsername(user.getNickName());

                List<Depttask> list1 = depttaskMapper.selectDepttaskList(temp);
                if(list1 != null && list1.size() > 0 ){
                    depttaskMapper.updateDepttask(temp);
                }else{
                    depttaskMapper.insertDepttask(temp);
                }

            }
        }

        return 1;
    }

    @Override
    public UserInfoDTO queryUserInfo(UserInfoDTO userInfoDTO) {

        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser sysUser = loginUser.getUser();

        if(userInfoDTO.getUserid() == null ){
            userInfoDTO.setUserid(sysUser.getUserId());
        }

        UserInfoDTO userInfoDTO1 = busitaskMapper.queryUserDeptinfo(userInfoDTO) ;
        List<SysPost> postList = busitaskMapper.queryUserPostInfo(userInfoDTO);
        userInfoDTO1.setPostList(postList);
        userInfoDTO1.setName(sysUser.getNickName());
        userInfoDTO1.setPhonenumber(sysUser.getPhonenumber());
        userInfoDTO1.setUserid(sysUser.getUserId());
        userInfoDTO1.setQdsbz(sysUser.getQdsbz());
        return userInfoDTO1 ;

    }

    /**
     * 查询部门和业务员目标汇报情况
     * @param taskDTO
     * @return
     */
    @Override
    public TaskDTO queryDeptBusiTask(TaskDTO taskDTO) {

        TaskDTO taskDTO1 = new TaskDTO();
        TaskDTO taskDTO2 = busitaskMapper.queryUserTask(taskDTO);
        if(taskDTO2 != null){
            BeanUtils.copyProperties(taskDTO2,taskDTO1);
        }
        List<Busitask>  busitaskList = busitaskMapper.queryUserBusiTask(taskDTO);
        if(taskDTO1 != null ){
            taskDTO1.setBusitaskList(busitaskList);
        }

        return taskDTO1;
    }

    /**
     * 查询今日业绩
     * @param jryjDTO
     * @return
     */
    @Override
    public JryjDTO queryJryj(JryjDTO jryjDTO) {
        String rqflag = jryjDTO.getRqflag() ;
        Date date = jryjDTO.getKtdate();
        Date date1 = DateUtils.addMonths(date,-1);
        Date date2 = DateUtils.addYears(date,-1 );
        Date yestoday = DateUtils.addDays(date, -1 );

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        //获得本月第一天
        calendar.add(Calendar.MONTH, 0);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        //将小时至0
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        //将分钟至0
        calendar.set(Calendar.MINUTE, 0);
        //将秒至0
        calendar.set(Calendar.SECOND,0);
        //将毫秒至0
        calendar.set(Calendar.MILLISECOND, 0);

        Date firstDay = calendar.getTime();
        //将当前月加1；
        calendar.add(Calendar.MONTH, 1);
        //在当前月的下一月基础上减去1毫秒
        calendar.add(Calendar.MILLISECOND, -1);
        Date lastDay = calendar.getTime();

        calendar.setTime(date1);

        calendar.add(Calendar.MONTH, 0);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        //将小时至0
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        //将分钟至0
        calendar.set(Calendar.MINUTE, 0);
        //将秒至0
        calendar.set(Calendar.SECOND,0);
        //将毫秒至0
        calendar.set(Calendar.MILLISECOND, 0);

        Date sfirstDay = calendar.getTime();
        //将当前月加1；
        calendar.add(Calendar.MONTH, 1);
        //在当前月的下一月基础上减去1毫秒
        calendar.add(Calendar.MILLISECOND, -1);
        Date slastDay = calendar.getTime();

        //获得本月最后一天

        //获取当年第一天和最后一天

        calendar.setTime(date);
        // 获取传入日期所在年的第一天
        int last = calendar.getActualMinimum(Calendar.DAY_OF_YEAR);
        calendar.set(Calendar.DAY_OF_YEAR, last);
        Date yearFirstDay = calendar.getTime();
        //获取传入日期所在年的最后一天
        calendar.add(Calendar.YEAR,1);
        calendar.add(Calendar.MILLISECOND,-1);
        Date yearLastDay = calendar.getTime();

        calendar.setTime(date2);
        // 获取传入日期所在年的第一天
        int last1 = calendar.getActualMinimum(Calendar.DAY_OF_YEAR);
        calendar.set(Calendar.DAY_OF_YEAR, last1);
        Date yearFirstDay1 = calendar.getTime();
        //获取传入日期所在年的最后一天
        calendar.add(Calendar.YEAR,1);
        calendar.add(Calendar.MILLISECOND,-1);
        Date yearLastDay1 = calendar.getTime();
        jryjDTO.setDate(date);
        jryjDTO.setFirstDay(firstDay);
        jryjDTO.setLastDay(lastDay);
        jryjDTO.setYearFirstDay(yearFirstDay);
        jryjDTO.setYearLastDay(yearLastDay);
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        jryjDTO.setDeptStart(String.valueOf(loginUser.getUser().getDeptId()).substring(0,1));
        JryjDTO jryjDTO1 = busitaskMapper.queryBusiTaskTotal(jryjDTO);
        if(jryjDTO1 != null){
            jryjDTO.setTodayTotal(jryjDTO1.getTotal());
        }else{
            jryjDTO.setTodayTotal(BigDecimal.ZERO);
        }
        jryjDTO.setDate(yestoday);
        jryjDTO.setFirstDay(sfirstDay);
        jryjDTO.setLastDay(slastDay);
        jryjDTO.setYearFirstDay(yearFirstDay1);
        jryjDTO.setYearLastDay(yearLastDay1);
        jryjDTO.setDeptStart(String.valueOf(loginUser.getUser().getDeptId()).substring(0,1));
        JryjDTO jryjDTO2 = busitaskMapper.queryBusiTaskTotal(jryjDTO);
        if(jryjDTO2 != null){
            jryjDTO.setYestodyTotal(jryjDTO2.getTotal());
        }else{
            jryjDTO.setYestodyTotal(BigDecimal.ZERO);
        }
        if(jryjDTO.getYestodyTotal() != null && jryjDTO.getYestodyTotal().compareTo(BigDecimal.ZERO) > 0 && jryjDTO.getTodayTotal() != null  ){
            BigDecimal zzje = jryjDTO.getTodayTotal().subtract(jryjDTO.getYestodyTotal());
            BigDecimal zzl = zzje.divide(jryjDTO.getYestodyTotal(),4,BigDecimal.ROUND_HALF_UP);
            jryjDTO.setZzl(zzl.multiply(new BigDecimal(100)));
        }else{
            jryjDTO.setZzl(BigDecimal.ZERO);
        }

        jryjDTO.setDate(date);
        jryjDTO.setFirstDay(firstDay);
        jryjDTO.setLastDay(lastDay);
        JryjDTO jryjDTO3 = busitaskMapper.queryToadyNo1(jryjDTO);

        if(jryjDTO3 != null){
            jryjDTO.setFirstName(jryjDTO3.getFirstName());
        }

        List<DeptArchDTO> deptArchDTOList = busitaskMapper.queryDeptArchTotal(jryjDTO);
        jryjDTO.setDeptArchDTOList(deptArchDTOList);
        return jryjDTO;
    }

    // 查询业务员日排行
    @Override
    public YwyAchDTO queryYwyAchievements(YwyAchDTO ywyAchDTO) throws ParseException {

        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        ywyAchDTO.setDeptStart(String.valueOf(loginUser.getUser().getDeptId()).substring(0,1));
        List<AchDetailDTO> rphList = busitaskMapper.queryRphValue(ywyAchDTO);

        if(rphList != null && rphList.size() > 0){
            Calendar calendar = Calendar.getInstance();
            Date date = ywyAchDTO.getStartDate();
            calendar.setTime(date);
            //获取月份
            Integer day = calendar.get(Calendar.DATE);
            String weekflag = "";
            if(day >= 1 && day <=8 ){
                weekflag = "1";
            }
            if(day >=9 && day <= 15 ){
                weekflag = "2";
            }
            if(day >=16 && day <= 23 ){
                weekflag = "3";
            }
            if(day >=24  ){
                weekflag = "4";
            }

            //获得本月第一天
            calendar.add(Calendar.MONTH, 0);
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            //将小时至0
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            //将分钟至0
            calendar.set(Calendar.MINUTE, 0);
            //将秒至0
            calendar.set(Calendar.SECOND,0);
            //将毫秒至0
            calendar.set(Calendar.MILLISECOND, 0);

            Date firstDay = calendar.getTime();
            //将当前月加1；
            calendar.add(Calendar.MONTH, 1);
            //在当前月的下一月基础上减去1毫秒
            calendar.add(Calendar.MILLISECOND, -1);
            Date lastDay = calendar.getTime();

            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
            SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd");

            Long ssyf = Long.valueOf(sdf.format(date));
            for(AchDetailDTO temp : rphList){
                Busitask busitask = new Busitask();
                busitask.setUserid(temp.getUserid());
                busitask.setSsyf(ssyf);
                List<Busitask> busitaskList = busitaskMapper.selectBusitaskList(busitask);
                BigDecimal total = temp.getTotal();
                if(busitaskList != null && busitaskList.size() >0 ){
                    BigDecimal tasknum = busitaskList.get(0).getTasknum();
                    BigDecimal firstTaskNum = busitaskList.get(0).getFirstTaskNum();
                    BigDecimal secondTaskNum = busitaskList.get(0).getSecondTaskNum();
                    BigDecimal thirdTaskNum = busitaskList.get(0).getThirdTaskNum();
                    BigDecimal fourthTaskNum = busitaskList.get(0).getFourthTaskNum();
                    if(total != null && tasknum != null && tasknum.compareTo(BigDecimal.ZERO) > 0){
                        BigDecimal totalWcl = total.divide(tasknum,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
                        temp.setTotalWcl(totalWcl);
                    }

                    if("1".equals(weekflag)){
                        String startStr = sdf.format(date) + "01";
                        String endStr = sdf.format(date) + "08";
                        Long userid = temp.getUserid();
                        ParamDTO paramDTO = new ParamDTO() ;
                        paramDTO.setStartDate(sdf1.parse(startStr));
                        paramDTO.setEndDate(sdf1.parse(endStr));
                        paramDTO.setUserid(userid);
                        Achievements achievements = busitaskMapper.queryUserWeekTask(paramDTO);
                        if(achievements != null){
                            BigDecimal weekTotal = achievements.getZje();
                            if(weekTotal != null && firstTaskNum != null && firstTaskNum.compareTo(BigDecimal.ZERO) > 0){
                                BigDecimal weekwcl = weekTotal.divide(firstTaskNum,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
                                temp.setWeekWcl(weekwcl);
                            }
                        }
                    }

                    if("2".equals(weekflag)){
                        String startStr = sdf.format(date) + "09";
                        String endStr = sdf.format(date) + "15";
                        Long userid = temp.getUserid();
                        ParamDTO paramDTO = new ParamDTO() ;
                        paramDTO.setStartDate(sdf1.parse(startStr));
                        paramDTO.setEndDate(sdf1.parse(endStr));
                        paramDTO.setUserid(userid);
                        Achievements achievements = busitaskMapper.queryUserWeekTask(paramDTO);
                        if(achievements != null){
                            BigDecimal weekTotal = achievements.getZje();
                            if(weekTotal != null && secondTaskNum != null && secondTaskNum.compareTo(BigDecimal.ZERO) > 0){
                                BigDecimal weekwcl = weekTotal.divide(secondTaskNum,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
                                temp.setWeekWcl(weekwcl);
                            }
                        }

                    }

                    if("3".equals(weekflag)){
                        String startStr = sdf.format(date) + "16";
                        String endStr = sdf.format(date) + "23";
                        Long userid = temp.getUserid();
                        ParamDTO paramDTO = new ParamDTO() ;
                        paramDTO.setStartDate(sdf1.parse(startStr));
                        paramDTO.setEndDate(sdf1.parse(endStr));
                        paramDTO.setUserid(userid);
                        Achievements achievements = busitaskMapper.queryUserWeekTask(paramDTO);
                        if(achievements != null){
                            BigDecimal weekTotal = achievements.getZje();
                            if(weekTotal != null && thirdTaskNum != null && thirdTaskNum.compareTo(BigDecimal.ZERO) > 0){
                                BigDecimal weekwcl = weekTotal.divide(thirdTaskNum,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
                                temp.setWeekWcl(weekwcl);
                            }
                        }

                    }
                    if("4".equals(weekflag)){
                        String startStr = sdf.format(date) + "24";
                        String endStr = sdf1.format(lastDay);
                        Long userid = temp.getUserid();
                        ParamDTO paramDTO = new ParamDTO() ;
                        paramDTO.setStartDate(sdf1.parse(startStr));
                        paramDTO.setEndDate(sdf1.parse(endStr));
                        paramDTO.setUserid(userid);
                        Achievements achievements = busitaskMapper.queryUserWeekTask(paramDTO);
                        if(achievements != null){
                            BigDecimal weekTotal = achievements.getZje();
                            if(weekTotal != null && fourthTaskNum != null && fourthTaskNum.compareTo(BigDecimal.ZERO) > 0){
                                BigDecimal weekwcl = weekTotal.divide(fourthTaskNum,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
                                temp.setWeekWcl(weekwcl);
                            }
                        }

                    }
                }
            }

        }
        // List<AchDetailDTO> achDetailDTOList  = busitaskMapper.queryAchDetail(ywyAchDTO);
        ywyAchDTO.setAchDetailDTOList(rphList);

        return ywyAchDTO;
    }

    @Override
    @DataScope(deptAlias = "d", userAlias = "u")
    public YwyAchDTO queryMonthRanking(YwyAchDTO ywyAchDTO) throws ParseException {
        Long ssyf = ywyAchDTO.getSsyf() ;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
        Date date = sdf.parse(String.valueOf(ssyf));
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        //获得本月第一天
        calendar.add(Calendar.MONTH, 0);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        //将小时至0
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        //将分钟至0
        calendar.set(Calendar.MINUTE, 0);
        //将秒至0
        calendar.set(Calendar.SECOND,0);
        //将毫秒至0
        calendar.set(Calendar.MILLISECOND, 0);

        Date firstDay = calendar.getTime();
        //将当前月加1；
        calendar.add(Calendar.MONTH, 1);
        //在当前月的下一月基础上减去1毫秒
        calendar.add(Calendar.MILLISECOND, -1);
        Date lastDay = calendar.getTime();

        ywyAchDTO.setStartDate(firstDay);
        ywyAchDTO.setEndDate(lastDay);

        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        ywyAchDTO.setDeptStart(String.valueOf(loginUser.getUser().getDeptId()).substring(0,1));
        List<AchDetailDTO> yphList = busitaskMapper.queryRphValue(ywyAchDTO);

        if(yphList != null && yphList.size() > 0 ){
            for(AchDetailDTO temp : yphList){
                Busitask busitask = new Busitask();
                busitask.setUserid(temp.getUserid());
                busitask.setSsyf(ssyf);
                List<Busitask> busitaskList = busitaskMapper.selectBusitaskList(busitask);
                BigDecimal total = temp.getTotal();
                if(busitaskList != null && busitaskList.size() >0 ){
                    BigDecimal tasknum = busitaskList.get(0).getTasknum();
                    temp.setTaskNum(tasknum);
                    if(total != null && tasknum != null && tasknum.compareTo(BigDecimal.ZERO) > 0){
                        BigDecimal totalWcl = total.divide(tasknum,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
                        temp.setTotalWcl(totalWcl);
                    }
                }
            }
        }
        ywyAchDTO.setAchDetailDTOList(yphList);
        return ywyAchDTO;
    }

    @Override
    @DataScope(deptAlias = "d", userAlias = "u")
    public YwyAchDTO queryWeekRanking(YwyAchDTO ywyAchDTO) throws ParseException {

        Long ssyf = ywyAchDTO.getSsyf() ;
        String weekflag = ywyAchDTO.getWeekflag() ;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd");
        Date date = sdf.parse(String.valueOf(ssyf));
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        //获得本月第一天
        calendar.add(Calendar.MONTH, 0);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        //将小时至0
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        //将分钟至0
        calendar.set(Calendar.MINUTE, 0);
        //将秒至0
        calendar.set(Calendar.SECOND,0);
        //将毫秒至0
        calendar.set(Calendar.MILLISECOND, 0);

        Date firstDay = calendar.getTime();
        //将当前月加1；
        calendar.add(Calendar.MONTH, 1);
        //在当前月的下一月基础上减去1毫秒
        calendar.add(Calendar.MILLISECOND, -1);
        Date lastDay = calendar.getTime();

        if("1".equals(weekflag)){
            String startStr = String.valueOf(ssyf) + "01";
            String endStr = String.valueOf(ssyf) + "08";
            ywyAchDTO.setStartDate(sdf1.parse(startStr));
            ywyAchDTO.setEndDate(sdf1.parse(endStr));
        }
        if("2".equals(weekflag)){
            String startStr = String.valueOf(ssyf) + "09";
            String endStr = String.valueOf(ssyf) + "15";
            ywyAchDTO.setStartDate(sdf1.parse(startStr));
            ywyAchDTO.setEndDate(sdf1.parse(endStr));
        }
        if("3".equals(weekflag)){
            String startStr = String.valueOf(ssyf) + "16";
            String endStr = String.valueOf(ssyf) + "23";
            ywyAchDTO.setStartDate(sdf1.parse(startStr));
            ywyAchDTO.setEndDate(sdf1.parse(endStr));
        }
        if("4".equals(weekflag)){
            String startStr = String.valueOf(ssyf) + "24";
            ywyAchDTO.setStartDate(sdf1.parse(startStr));
            ywyAchDTO.setEndDate(lastDay);
        }

        List<AchDetailDTO> yphList = busitaskMapper.queryRphValue(ywyAchDTO);

        if(yphList != null && yphList.size() > 0 ){
            for(AchDetailDTO temp : yphList){
                Busitask busitask = new Busitask();
                busitask.setUserid(temp.getUserid());
                busitask.setSsyf(ssyf);
                List<Busitask> busitaskList = busitaskMapper.selectBusitaskList(busitask);
                BigDecimal total = temp.getTotal();

                if(busitaskList != null && busitaskList.size() >0 ){

                    BigDecimal firstTaskNum = busitaskList.get(0).getFirstTaskNum();
                    BigDecimal secondTaskNum = busitaskList.get(0).getSecondTaskNum();
                    BigDecimal thirdTaskNum = busitaskList.get(0).getThirdTaskNum();
                    BigDecimal fourthTaskNum = busitaskList.get(0).getFourthTaskNum();

                    if("1".equals(weekflag)){
                        temp.setTaskNum(firstTaskNum);
                       if(firstTaskNum != null && firstTaskNum.compareTo(BigDecimal.ZERO) > 0 && temp.getTotal() != null ){
                           if(total != null && firstTaskNum != null && firstTaskNum.compareTo(BigDecimal.ZERO) > 0){
                               BigDecimal weekWcl = total.divide(firstTaskNum,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
                               temp.setWeekWcl(weekWcl);
                           }
                       }else{
                           temp.setWeekWcl(BigDecimal.ZERO);
                       }
                    }

                    if("2".equals(weekflag)){
                        temp.setTaskNum(secondTaskNum);
                        if(secondTaskNum != null && secondTaskNum.compareTo(BigDecimal.ZERO) > 0 && temp.getTotal() != null ){
                            if(total != null && secondTaskNum != null && secondTaskNum.compareTo(BigDecimal.ZERO) > 0){
                                BigDecimal weekWcl = total.divide(secondTaskNum,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
                                temp.setWeekWcl(weekWcl);
                            }
                        }else{
                            temp.setWeekWcl(BigDecimal.ZERO);
                        }

                    }

                    if("3".equals(weekflag)){
                        temp.setTaskNum(thirdTaskNum);
                        if(thirdTaskNum != null && thirdTaskNum.compareTo(BigDecimal.ZERO) > 0 && temp.getTotal() != null ){
                            if(total != null && thirdTaskNum != null && thirdTaskNum.compareTo(BigDecimal.ZERO) > 0){
                                BigDecimal weekWcl = total.divide(thirdTaskNum,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
                                temp.setWeekWcl(weekWcl);
                            }
                        }else{
                            temp.setWeekWcl(BigDecimal.ZERO);
                        }

                    }
                    if("4".equals(weekflag)){
                        temp.setTaskNum(fourthTaskNum);
                        if(fourthTaskNum != null && fourthTaskNum.compareTo(BigDecimal.ZERO) > 0 && temp.getTotal() != null ){
                            if(total != null && fourthTaskNum != null && fourthTaskNum.compareTo(BigDecimal.ZERO) > 0){
                                BigDecimal weekWcl = total.divide(fourthTaskNum,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
                                temp.setWeekWcl(weekWcl);
                            }
                        }else{
                            temp.setWeekWcl(BigDecimal.ZERO);
                        }
                    }
                }
            }
        }
        ywyAchDTO.setAchDetailDTOList(yphList);
        return ywyAchDTO;
    }

    /**
     * 查询本月进展情况
     * @param monthStaticsDTO
     * @return
     */
    @Override
    @DataScope(deptAlias = "d", userAlias = "u")
    public MonthStaticsDTO queryMonthStatics(MonthStaticsDTO monthStaticsDTO) throws ParseException {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        ParamDTO paramDTO = new ParamDTO();
        Long ssyf = monthStaticsDTO.getSsyf() ;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd");

        Date date = sdf.parse(String.valueOf(ssyf));
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);

        calendar.add(Calendar.MONTH, 0);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        //将小时至0
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        //将分钟至0
        calendar.set(Calendar.MINUTE, 0);
        //将秒至0
        calendar.set(Calendar.SECOND,0);
        //将毫秒至0
        calendar.set(Calendar.MILLISECOND, 0);

        Date firstDay = calendar.getTime();
        //将当前月加1；
        calendar.add(Calendar.MONTH, 1);
        //在当前月的下一月基础上减去1毫秒
        calendar.add(Calendar.MILLISECOND, -1);
        Date lastDay = calendar.getTime();

        paramDTO.setStartDate(firstDay);
        paramDTO.setEndDate(lastDay);
        paramDTO.setDeptid(monthStaticsDTO.getDeptid());
        paramDTO.setSsyf(monthStaticsDTO.getSsyf());
        paramDTO.setDeptStart(String.valueOf(loginUser.getUser().getDeptId()).substring(0,1));
        // 查询销售额总数
        MonthStaticsDTO monthStaticsDTO1 = busitaskMapper.queryMonthStatics(paramDTO);
        if(monthStaticsDTO1 != null ){
            monthStaticsDTO.setTotal(monthStaticsDTO1.getTotal());
        }else{
            monthStaticsDTO.setTotal(BigDecimal.ZERO);
        }
        // 查询部门任务数
        MonthStaticsDTO monthStaticsDTO2 = busitaskMapper.queryDeptBusiTask(paramDTO);
        if(monthStaticsDTO2 != null ){
            monthStaticsDTO.setTaskNum(monthStaticsDTO2.getTaskNum());
            monthStaticsDTO.setFirstTaskNum(monthStaticsDTO2.getFirstTaskNum());
            monthStaticsDTO.setSecondTaskNum(monthStaticsDTO2.getSecondTaskNum());
            monthStaticsDTO.setThirdTaskNum(monthStaticsDTO2.getThirdTaskNum());
            monthStaticsDTO.setFourthTaskNum(monthStaticsDTO2.getFourthTaskNum());
        }else{
            monthStaticsDTO.setTaskNum(BigDecimal.ZERO);
            monthStaticsDTO.setFirstTaskNum(BigDecimal.ZERO);
            monthStaticsDTO.setSecondTaskNum(BigDecimal.ZERO);
            monthStaticsDTO.setThirdTaskNum(BigDecimal.ZERO);
            monthStaticsDTO.setFourthTaskNum(BigDecimal.ZERO);
        }
        //计算完成率
        if(monthStaticsDTO.getTotal() != null && monthStaticsDTO.getTaskNum() != null && monthStaticsDTO.getTaskNum().compareTo(BigDecimal.ZERO) > 0){
            BigDecimal totalWcl = monthStaticsDTO.getTotal().divide(monthStaticsDTO.getTaskNum(),4,BigDecimal.ROUND_HALF_UP);
            monthStaticsDTO.setTotalWcl(totalWcl);
        }else{
            monthStaticsDTO.setTotalWcl(BigDecimal.ZERO);
        }

        //1-8号
        String startStr1 = String.valueOf(ssyf) + "01";
        String endStr1 = String.valueOf(ssyf) + "08" ;
        Date startDate1 = sdf1.parse(startStr1);
        Date endDate1 = sdf1.parse(endStr1);
        paramDTO.setStartDate(startDate1);
        paramDTO.setEndDate(endDate1);
        MonthStaticsDTO monthStaticsDTOFirst = busitaskMapper.queryMonthStatics(paramDTO);
        if(monthStaticsDTOFirst != null){
            monthStaticsDTO.setFirstTotal(monthStaticsDTOFirst.getTotal());
            if(monthStaticsDTO.getFirstTotal() != null && monthStaticsDTO.getFirstTaskNum() != null && monthStaticsDTO.getFirstTaskNum().compareTo(BigDecimal.ZERO) > 0){
                BigDecimal firstWcl =monthStaticsDTO.getFirstTotal().divide(monthStaticsDTO.getFirstTaskNum(),4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
                monthStaticsDTO.setFirstWcl(firstWcl);
            }else {
                monthStaticsDTO.setFirstWcl(BigDecimal.ZERO);
            }
        }else{
            monthStaticsDTO.setFirstTotal(BigDecimal.ZERO);
            monthStaticsDTO.setFirstWcl(BigDecimal.ZERO);
        }

        //9-15号
        String startStr2 = String.valueOf(ssyf) + "09";
        String endStr2 = String.valueOf(ssyf) + "15" ;
        Date startDate2 = sdf1.parse(startStr2);
        Date endDate2 = sdf1.parse(endStr2);
        paramDTO.setStartDate(startDate2);
        paramDTO.setEndDate(endDate2);
        MonthStaticsDTO monthStaticsDTOSecond = busitaskMapper.queryMonthStatics(paramDTO);
        if(monthStaticsDTOSecond != null){
            monthStaticsDTO.setSecondTotal(monthStaticsDTOSecond.getTotal());
            if(monthStaticsDTO.getSecondTotal() != null && monthStaticsDTO.getSecondTaskNum() != null && monthStaticsDTO.getSecondTaskNum().compareTo(BigDecimal.ZERO) > 0){
                BigDecimal secondWcl =monthStaticsDTO.getSecondTotal().divide(monthStaticsDTO.getSecondTaskNum(),4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
                monthStaticsDTO.setSecondWcl(secondWcl);
            }else {
                monthStaticsDTO.setSecondWcl(BigDecimal.ZERO);
            }
        }else{
            monthStaticsDTO.setSecondTotal(BigDecimal.ZERO);
            monthStaticsDTO.setSecondWcl(BigDecimal.ZERO);
        }

        //16-23号
        String startStr3 = String.valueOf(ssyf) + "16";
        String endStr3 = String.valueOf(ssyf) + "23" ;
        Date startDate3 = sdf1.parse(startStr3);
        Date endDate3 = sdf1.parse(endStr3);
        paramDTO.setStartDate(startDate3);
        paramDTO.setEndDate(endDate3);
        MonthStaticsDTO monthStaticsDTOThird = busitaskMapper.queryMonthStatics(paramDTO);
        if(monthStaticsDTOThird != null){
            monthStaticsDTO.setThirdTotal(monthStaticsDTOThird.getTotal());
            if(monthStaticsDTO.getThirdTotal() != null && monthStaticsDTO.getThirdTaskNum() != null && monthStaticsDTO.getThirdTaskNum().compareTo(BigDecimal.ZERO) > 0){
                BigDecimal thirdWcl =monthStaticsDTO.getThirdTotal().divide(monthStaticsDTO.getThirdTaskNum(),4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
                monthStaticsDTO.setThirdWcl(thirdWcl);
            }else {
                monthStaticsDTO.setThirdWcl(BigDecimal.ZERO);
            }
        }else {
            monthStaticsDTO.setThirdTotal(BigDecimal.ZERO);
            monthStaticsDTO.setThirdWcl(BigDecimal.ZERO);
        }

        //24号以后
        String startStr4 = String.valueOf(ssyf) + "24";
        Date startDate4 = sdf1.parse(startStr4);
        paramDTO.setStartDate(startDate4);
        paramDTO.setEndDate(lastDay);
        MonthStaticsDTO monthStaticsDTOFourth = busitaskMapper.queryMonthStatics(paramDTO);
        if(monthStaticsDTOFourth != null){
            monthStaticsDTO.setFourthTotal(monthStaticsDTOFourth.getTotal());
            if(monthStaticsDTO.getFourthTotal() != null && monthStaticsDTO.getFourthTaskNum() != null && monthStaticsDTO.getFourthTaskNum().compareTo(BigDecimal.ZERO) > 0){
                BigDecimal fourthWcl =monthStaticsDTO.getFourthTotal().divide(monthStaticsDTO.getFourthTaskNum(),4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
                monthStaticsDTO.setFourthWcl(fourthWcl);
            }else {
                monthStaticsDTO.setFourthWcl(BigDecimal.ZERO);
            }
        }else {
            monthStaticsDTO.setFourthTotal(BigDecimal.ZERO);
            monthStaticsDTO.setFourthWcl(BigDecimal.ZERO);
        }
        return monthStaticsDTO;
    }

    @Override
    public TaskStaticsDTO queryTaskStatics(TaskStaticsDTO taskStaticsDTO) {

        Date date = new Date();
        Date nextDate = DateUtils.addMonths(date,1);
        SimpleDateFormat sdf = new SimpleDateFormat( "yyyyMM");
        Long ssyf = Long.valueOf(sdf.format(date));
        taskStaticsDTO.setSsyf(ssyf);
        // 查询下个月已填报
        TaskStaticsDTO taskStaticsDTO1 = busitaskMapper.queryNextMonthBusiTask(taskStaticsDTO);
        if(taskStaticsDTO1 != null){
            taskStaticsDTO.setYtbTaskNum( taskStaticsDTO1.getYtbTaskNum());
            taskStaticsDTO.setYtbFirstTaskNum(taskStaticsDTO1.getYtbFirstTaskNum());
            taskStaticsDTO.setYtbSecondTaskNum(taskStaticsDTO1.getYtbSecondTaskNum());
            taskStaticsDTO.setYtbThirdTaskNum(taskStaticsDTO1.getYtbThirdTaskNum());
            taskStaticsDTO.setYtbFourthTaskNum(taskStaticsDTO1.getYtbFourthTaskNum());
        }
        // 查询下个月部门任务
        TaskStaticsDTO taskStaticsDTO2 = busitaskMapper.queryNextMonthDeptTask(taskStaticsDTO);
        if(taskStaticsDTO2 != null){
            taskStaticsDTO.setTaskNum(taskStaticsDTO2.getTaskNum());
            taskStaticsDTO.setFirstTaskNum(taskStaticsDTO2.getFirstTaskNum());
            taskStaticsDTO.setSecondTaskNum(taskStaticsDTO2.getSecondTaskNum());
            taskStaticsDTO.setThirdTaskNum(taskStaticsDTO2.getThirdTaskNum());
            taskStaticsDTO.setFourthTaskNum(taskStaticsDTO2.getFourthTaskNum());
        }

        // 查询已填报和未填报人数
        TaskStaticsDTO taskStaticsDTO3 = busitaskMapper.queryXiaoshouRs(taskStaticsDTO);
        if(taskStaticsDTO3  != null){
            taskStaticsDTO.setZrs(taskStaticsDTO3.getZrs());
        }

        TaskStaticsDTO taskStaticsDTO4 = busitaskMapper.queryYtbRs(taskStaticsDTO);
        if(taskStaticsDTO4 != null ){
            taskStaticsDTO.setYtbrs(taskStaticsDTO4.getYtbrs());
        }

        if(taskStaticsDTO.getZrs() != null && taskStaticsDTO.getYtbrs() != null ){
            taskStaticsDTO.setWtbrs(taskStaticsDTO.getZrs() - taskStaticsDTO.getYtbrs() );
        }

        // 查询图标所需数据
        List<DeptArchDTO> list = busitaskMapper.queryDeptUsers(taskStaticsDTO);

        if(list != null && list.size() > 0 ){
            for(DeptArchDTO temp : list ){
                BigDecimal zrs = temp.getValue() ;
                ParamDTO paramDTO = new ParamDTO();
                paramDTO.setDeptid(temp.getDeptid());
                paramDTO.setSsyf(taskStaticsDTO.getSsyf());
                TaskStaticsDTO ytbTaskStaticsDTO = busitaskMapper.queryDeptYtbRs(paramDTO);
                if(ytbTaskStaticsDTO != null ){
                    Integer ytbrs = ytbTaskStaticsDTO.getYtbrs() ;
                    temp.setValue(new BigDecimal(ytbrs));
                    if(ytbrs != null && zrs != null && zrs.compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal wcl = new BigDecimal(ytbrs).divide(zrs,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
                        temp.setWcl(wcl);
                    }
                }
            }
        }
        taskStaticsDTO.setList(list);
        return taskStaticsDTO;
    }

    // 查询部门业绩
    @Override
    public List<DeptArchDTO> queryDeptAchDetail(DeptArchDTO deptArchDTO) throws ParseException {


        String weekflag = deptArchDTO.getWeekflag() ;
        JryjDTO jryjDTO = new JryjDTO() ;
        jryjDTO.setDeptid(deptArchDTO.getDeptid());
        jryjDTO.setSsyf(deptArchDTO.getSsyf());
        Long ssyf = deptArchDTO.getSsyf() ;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
        Date date = sdf.parse(String.valueOf(ssyf));
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(Calendar.MONTH, 0);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        //将小时至0
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        //将分钟至0
        calendar.set(Calendar.MINUTE, 0);
        //将秒至0
        calendar.set(Calendar.SECOND,0);
        //将毫秒至0
        calendar.set(Calendar.MILLISECOND, 0);

        Date firstDay = calendar.getTime();
        //将当前月加1；
        calendar.add(Calendar.MONTH, 1);
        //在当前月的下一月基础上减去1毫秒
        calendar.add(Calendar.MILLISECOND, -1);
        Date lastDay = calendar.getTime();


        jryjDTO.setFirstDay(firstDay);
        jryjDTO.setLastDay(lastDay);

        if(StringUtils.isBlank(weekflag)){
            List<DeptArchDTO> list =  busitaskMapper.queryDeptArchDetail(jryjDTO);
            if(list != null && list.size() > 0 ){
                for(DeptArchDTO temp : list ){
                    BigDecimal zje = temp.getValue() ;
                    BigDecimal tasknum = temp.getTasknum() ;
                    if(zje != null && tasknum != null && tasknum.compareTo(BigDecimal.ZERO) > 0){
                        BigDecimal wcl = zje.divide(tasknum,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
                        temp.setWcl(wcl);
                    }else{
                        temp.setWcl(BigDecimal.ZERO);
                    }
                }
            }

            String sortflag = deptArchDTO.getSortflag();
            if("2".equals(sortflag)){
                Collections.sort(list, new Comparator<DeptArchDTO>() {
                    @Override
                    public int compare(DeptArchDTO o1, DeptArchDTO o2) {
                        if(o1.getWcl() != null && o2.getWcl() != null ){
                            if(o1.getWcl().compareTo(o2.getWcl()) >= 0 ){
                                return  -1 ;
                            }else{
                                return  1 ;
                            }

                        }else{
                            return 0;
                        }

                    }
                });
            }

            if("1".equals(sortflag)){
                Collections.sort(list, new Comparator<DeptArchDTO>() {
                    @Override
                    public int compare(DeptArchDTO o1, DeptArchDTO o2) {
                        if(o1.getValue() != null && o2.getValue() != null ){
                            if(o1.getValue().compareTo(o2.getValue()) >= 0 ){
                                return  -1 ;
                            }else{
                                return  1 ;
                            }

                        }else{
                            return 0;
                        }

                    }
                });
            }

            return list ;
        } else{
            SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd");
            List<DeptArchDTO> list = new ArrayList<DeptArchDTO>();
            if("1".equals(weekflag)){
                String startStr = String.valueOf(ssyf) + "01";
                String endStr = String.valueOf(ssyf) + "08";
                jryjDTO.setFirstDay(sdf1.parse(startStr));
                jryjDTO.setLastDay(sdf1.parse(endStr));
                list =  busitaskMapper.queryDeptArchDetail(jryjDTO);
                if(list != null && list.size() > 0 ){
                    for(DeptArchDTO temp : list ){
                        BigDecimal zje = temp.getValue() ;
                        BigDecimal firstTaskNum = temp.getFirstTaskNum() ;
                        if(zje != null && firstTaskNum != null && firstTaskNum.compareTo(BigDecimal.ZERO) > 0){
                            BigDecimal wcl = zje.divide(firstTaskNum,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
                            temp.setWcl(wcl);
                        }else{
                            temp.setWcl(BigDecimal.ZERO);
                        }
                    }
                }
            }
            if("2".equals(weekflag)){
                String startStr = String.valueOf(ssyf) + "09";
                String endStr = String.valueOf(ssyf) + "15";
                jryjDTO.setFirstDay(sdf1.parse(startStr));
                jryjDTO.setLastDay(sdf1.parse(endStr));
                list =  busitaskMapper.queryDeptArchDetail(jryjDTO);
                if(list != null && list.size() > 0 ){
                    for(DeptArchDTO temp : list ){
                        BigDecimal zje = temp.getValue() ;
                        BigDecimal secondTaskNum = temp.getSecondTaskNum() ;
                        if(zje != null && secondTaskNum != null && secondTaskNum.compareTo(BigDecimal.ZERO) > 0){
                            BigDecimal wcl = zje.divide(secondTaskNum,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
                            temp.setWcl(wcl);
                        }else{
                            temp.setWcl(BigDecimal.ZERO);
                        }
                    }
                }
            }
            if("3".equals(weekflag)){
                String startStr = String.valueOf(ssyf) + "16";
                String endStr = String.valueOf(ssyf) + "23";
                jryjDTO.setFirstDay(sdf1.parse(startStr));
                jryjDTO.setLastDay(sdf1.parse(endStr));
                list =  busitaskMapper.queryDeptArchDetail(jryjDTO);
                if(list != null && list.size() > 0 ){
                    for(DeptArchDTO temp : list ){
                        BigDecimal zje = temp.getValue() ;
                        BigDecimal thirdTaskNum = temp.getThirdTaskNum() ;
                        if(zje != null && thirdTaskNum != null && thirdTaskNum.compareTo(BigDecimal.ZERO) > 0){
                            BigDecimal wcl = zje.divide(thirdTaskNum,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
                            temp.setWcl(wcl);
                        }else{
                            temp.setWcl(BigDecimal.ZERO);
                        }
                    }
                }
            }
            if("4".equals(weekflag)){
                String startStr = String.valueOf(ssyf) + "24";
                jryjDTO.setFirstDay(sdf1.parse(startStr));
                jryjDTO.setLastDay(lastDay);
                list =  busitaskMapper.queryDeptArchDetail(jryjDTO);
                if(list != null && list.size() > 0 ){
                    for(DeptArchDTO temp : list ){
                        BigDecimal zje = temp.getValue() ;
                        BigDecimal fourthTaskNum = temp.getFourthTaskNum() ;
                        if(zje != null && fourthTaskNum != null && fourthTaskNum.compareTo(BigDecimal.ZERO) > 0){
                            BigDecimal wcl = zje.divide(fourthTaskNum,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
                            temp.setWcl(wcl);
                        }else{
                            temp.setWcl(BigDecimal.ZERO);
                        }
                    }
                }
            }
            return list;
        }
    }

    @Override
    public List<MonthStaticsDTO> queryDeptTaskDetail(MonthStaticsDTO monthStaticsDTO) {

        List<MonthStaticsDTO> list = busitaskMapper.queryDeptTaskDetail(monthStaticsDTO);
        if(list != null && list.size() > 0 ){
            for(MonthStaticsDTO temp : list ){
                monthStaticsDTO.setDeptid(temp.getDeptid());
                MonthStaticsDTO monthStaticsDTO1  = busitaskMapper.selectDeptTask(monthStaticsDTO);
                if(monthStaticsDTO1 != null  ){
                    temp.setTaskNum(monthStaticsDTO1.getTaskNum());
                    temp.setFirstTaskNum(monthStaticsDTO1.getFirstTaskNum());
                    temp.setSecondTaskNum(monthStaticsDTO1.getSecondTaskNum());
                    temp.setThirdTaskNum(monthStaticsDTO1.getThirdTaskNum());
                    temp.setFourthTaskNum(monthStaticsDTO1.getFourthTaskNum());
                }else{
                    temp.setTaskNum(BigDecimal.ZERO);
                    temp.setFirstTaskNum(BigDecimal.ZERO);
                    temp.setSecondTaskNum(BigDecimal.ZERO);
                    temp.setThirdTaskNum(BigDecimal.ZERO);
                    temp.setFourthTaskNum(BigDecimal.ZERO);
                }
            }
        }
        return list;
    }

    @Override
    public List<MonthStaticsDTO> queryPsnlTaskDetail(MonthStaticsDTO monthStaticsDTO) {

        String tbflag   = monthStaticsDTO.getTbflag() ;
        if("2".equals(tbflag)) {
            // 查询未填报人员情况
            List<MonthStaticsDTO> list = busitaskMapper.queryPsnlTaskDetail(monthStaticsDTO);
            return  list;
        }else{
            // 查询已填报人员情况
            List<MonthStaticsDTO> list1 = busitaskMapper.queryPsnlTaskDetailYb(monthStaticsDTO);
            return list1;
        }

    }

    @Override
    public YwyAchDTO queryYearRanking(YwyAchDTO ywyAchDTO) throws ParseException {

        Long ssnf = ywyAchDTO.getSsnf();
        String startStr = ssnf + "-" + "01-01 00:00:00";
        String endStr = ssnf + "-" + "12-31 23:59:59";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date startDate = sdf.parse(startStr);
        Date endDate = sdf.parse(endStr);
        ywyAchDTO.setStartDate(startDate);
        ywyAchDTO.setEndDate(endDate);
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        ywyAchDTO.setDeptStart(String.valueOf(loginUser.getUser().getDeptId()).substring(0,1));
        List<AchDetailDTO> nphList = busitaskMapper.queryYearValue(ywyAchDTO);
        ywyAchDTO.setAchDetailDTOList(nphList);
        return ywyAchDTO;
    }
}
